package com.orifine.sql.chain;

import com.orifine.orm.model.TableModel;
import com.orifine.sql.SyntaxString;

public class ChainJoin implements ChainSql {
	private ChainJoinType type;
	private String joinTableName;
	private ChainOn on;
	
	public ChainJoin(ChainJoinType type, TableModel joinTable, ChainOn on){
		this.type = type;
		this.joinTableName = joinTable.getName();
		this.on = on;
	}

	@Override
	public void chain(SyntaxString out) {
		switch(type){
		case FULL_JOIN:
			out.addWord("FULL").addWord("JOIN").addWord(joinTableName);
			break;
		case INNER_JOIN:
			out.addWord("INNER").addWord("JOIN").addWord(joinTableName);
			break;
		case LEFT_JOIN:
			out.addWord("LEFT").addWord("JOIN").addWord(joinTableName);
			break;
		case RIGHT_JOIN:
			out.addWord("RIGHT").addWord("JOIN").addWord(joinTableName);
			break;
		}
		on.chain(out);
	}

	@Override
	public String sql() {
		SyntaxString syntaxString = new SyntaxString();
		chain(syntaxString);
		return syntaxString.toString();
	}
}
